%% @author Administrator
%% @doc @todo Add description to user_svr_util.


-module(user_svr_util).

%% ====================================================================
%% API functions
%% ====================================================================

-export([get_pid_by_uid/1,
		 send_msg/2,
		 send_msg/3]).

-include("account.hrl").
-include("global.hrl").


%% ====================================================================
%% Internal functions
%% ====================================================================

%% @doc 通过玩家uid获取玩家pid
%% Return: Pid | undefined
get_pid_by_uid(Uid) ->
	case ets:lookup(?ETS_UID_PID, Uid) of
		[{Uid, Pid}|_] ->
			Pid;
		_ ->
			?undefined
	end.



%% @doc 玩家发送信息给客户端
send_msg(Uid, MsgId, Msg) ->
	case get_pid_by_uid(Uid) of
		Pid when is_port(Pid) ->
			Pid ! {send_client_msg, MsgId, Msg};
		_ ->
			pass
	end.
			
%% @doc 玩家发送信息给客户端(玩家进程)			
send_msg(MsgId, Msg) ->
	RouterPid = get(router_pid),	
	RouterPid ! {send_client_msg, MsgId, Msg}.



%% send_msg(Uid, Msg) ->
%% 	